#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>

#if defined(LINUX) || defined (DARWIN)
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <netinet/ip.h>
#include <netdb.h>
#endif
#ifdef LINUX
#include <linux/if_packet.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if.h>
#include <sys/sendfile.h>
#endif
#if defined(LINUX) || defined (DARWIN)
#include <sys/time.h>
#include <sys/uio.h>
#include <unistd.h>	
#include <fcntl.h>
#endif
#ifdef WIN32
#include <io.h>
#include <winsock2.h>
#include <Ws2tcpip.h>
#endif

#ifdef WIN32
#pragma  comment(lib, "ws2_32.lib")
#endif

#include "PlatformDiff.h"
#include "SocketType.h"


#ifndef __CLASS_SIMPLE_SOCKET_H__
#define __CLASS_SIMPLE_SOCKET_H__


EXTERN_C_BEGIN

struct _CSSocket;
typedef struct _CSSocket CSSocket;

DLL_API CSSocket* CSSocketCreate(SocketType sType);
DLL_API CSSocket* CSSocketAccept(CSSocket *pThiz);
DLL_API bool CSSocketListen(CSSocket *pThiz,const uint8_t *pAddr, int16_t iPort, int32_t iBacklog);
DLL_API bool CSSocketOpen(CSSocket *pThiz, const int8_t *pAddr, int16_t iPort);
DLL_API int32_t CSSocketReceive(CSSocket *pThiz, int8_t *pBuf, int32_t iSize);
DLL_API int32_t CSSocketSend(CSSocket *pThiz, const int8_t *pBuf, size_t bytesToSend);
DLL_API bool CSSocketClose(CSSocket **ppThiz);

DLL_API bool CSSocketIsValid(CSSocket *pThiz);
DLL_API SocketErrorType CSSocketGetError(CSSocket *pThiz);
DLL_API void CSSocketTranslateError(CSSocket *pThiz);
DLL_API bool CSSocketShutdown(CSSocket *pThiz, ShutdownMode nShutdown);
DLL_API uint8_t *CSSocketGetClientAddr(CSSocket *pThiz);
DLL_API int16_t CSSocketGetClientPort(CSSocket *pThiz);
DLL_API uint8_t *CSSocketGetServerAddr(CSSocket *pThiz);
DLL_API int16_t CSSocketGetServerPort(CSSocket *pThiz);
DLL_API struct sockaddr_in *CSSocketGetClientSockAddr(CSSocket *pThiz);
DLL_API struct sockaddr_in *CSSocketGetServerockAddr(CSSocket *pThiz);
DLL_API void CSSocketSetError(CSSocket *pThiz, SocketErrorType sErrorType);
DLL_API void CSSocketSetUdpConnect(CSSocket *pThiz, bool bConnect);

DLL_API SOCKET CSSocketGetDescriptor(CSSocket *pThiz);
DLL_API SocketType GetCSSocketType(CSSocket *pThiz);
DLL_API void CSSocketSetDescriptor(CSSocket* pThiz, SOCKET sock);

DLL_API int32_t CSSocketSize(void);

EXTERN_C_END

#endif
